<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改参赛作品')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-act-edit" th:object="${act}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="schoolId" th:field="*{schoolId}" type="hidden">
            <input name="facultyId" th:field="*{facultyId}" type="hidden">
            <input name="gameId" th:field="*{gameId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">学校：</label>
                <div class="col-sm-8">
                    <input name="school" th:field="*{school}" class="form-control" type="text" readonly="true" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">院系：</label>
                <div class="col-sm-8">
                    <input name="faculty" th:field="*{faculty}" class="form-control" type="text" readonly="true" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">大赛名称：</label>
                <div class="col-sm-8">
                    <input name="gameName" th:field="*{gameName}" class="form-control" type="text" readonly="true" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">作品类别：</label>
                <div class="col-sm-8">
                    <select class="form-control" id="categoryId" name="categoryId">
                        <block  th:each="category : ${categoryTree}">
                            <block th:if="${#lists.isEmpty(category.children)}">
                                <option  th:text="${category.name}" th:value="${category.id}" th:field="*{categoryId}"></option>
                            </block>
                            <block th:if="not ${#lists.isEmpty(category.children)}">
                                <optgroup th:label="${category.name}">
                                    <block  th:each="child : ${category.children}">
                                        <option  th:text="${child.name}" th:value="${child.id}" th:field="*{categoryId}"></option>
                                    </block>
                                </optgroup>
                            </block>
                        </block>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">命题名称：</label>
                <div class="col-sm-8">
                    <select id="titleId" name="titleId" class="form-control" th:with="titles=${titles}" required>
                        <option th:each="title : ${titles}" th:text="${title.title}" th:value="${title.id}" th:field="*{titleId}"></option>
                    </select>
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label">命题名称：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <textarea name="title" class="form-control">[[*{title}]]</textarea>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">参赛编号：</label>
                <div class="col-sm-8">
                    <input name="actNo" th:field="*{actNo}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">作品名称：</label>
                <div class="col-sm-8">
                    <textarea name="actName" class="form-control">[[*{actName}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">作者：</label>
                <div class="col-sm-8">
                    <input name="author" th:field="*{author}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">作者电话：</label>
                <div class="col-sm-8">
                    <input name="authorPhone" th:field="*{authorPhone}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">指导老师：</label>
                <div class="col-sm-8">
                    <input name="teacher" th:field="*{teacher}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">指导老师电话：</label>
                <div class="col-sm-8">
                    <input name="teacherPhone" th:field="*{teacherPhone}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">专业：</label>
                <div class="col-sm-8">
                    <input name="major" th:field="*{major}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">其他：</label>
                <div class="col-sm-8">
                    <textarea name="remark"  th:field="*{remark}" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/act";
        $("#form-act-edit").validate({
            focusCleanup: true
        });

        $(function(){
            $("#categoryId").change(function(){
                changeTitle();
            })
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-act-edit').serialize());
            }
        }


        function changeTitle(){
            var gameId = $("#gameId").val();
            var categoryId =  $("#categoryId").val();
            $.post(ctx + "system/title/selectByGameIdAndCategoryId?gameId=" + gameId + "&categoryId=" + categoryId,{},
                function(response){
                    console.log(response)
                    $("#titleId").html("<option value=''>-- 请选择命题 --</option>")//清空下拉框
                    var result = response.data;
                    console.log(response)
                    for (var i = 0; i < result.length; i++) {
                        var option = $("<option></option>").text(result[i].title);
                        option.attr("value", result[i].id);
                        $("#titleId").append(option);
                    }
                });
        }
    </script>
</body>
</html>
